# -*- coding: utf-8 -*-
# @file    : config.py
# @Date    : 2020/10/21
# @Author  :
# @Version : 1.0.0
import yaml


class Config(object):
    """
    加载配置
    """

    def __init__(self, file_name):
        print("[配置文件] 加载中 ...")
        self.file_name = file_name
        self.data = {}
        self.reload()
        print("[配置文件] 成功! (%s)" % file_name)

    def __getitem__(self, item):
        return self.data[item]

    def keys(self):
        yield from self.data

    def reload(self):
        with open(self.file_name, 'r', encoding="utf-8") as f:
            self.data = yaml.safe_load(f)
